import org.junit.Test;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public class byteToHexString {

    public static String byteArrayToHexStr(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }
        char[] hexArray = "0123456789ABCDEF".toCharArray();
        char[] hexChars = new char[byteArray.length * 2];
        for (int j = 0; j < byteArray.length; j++) {
            int v = byteArray[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

    @Test
    public void test1() {
//        CompletableFuture.su(new Runnable() {
//            @Override
//            public void run() {
//                try {
//                    System.out.println("sleep start");
//                    Thread.sleep(3000);
//                    System.out.println("sleep end");
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        });

        CompletableFuture.supplyAsync(new Supplier<Object>() {
            @Override
            public Object get() {
                System.out.println("sleep start");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("sleep end");
                return null;
            }
        });
//        Timer timer = new Timer();// 实例化Timer类
//        timer.schedule(new TimerTask() {
//            public void run() {
//                System.out.println("task done");
//                this.cancel();
//            }
//        }, 5000);// 这里百毫秒
        System.out.println("main done");
    }
}
